package com.controller;

import com.entity.Student;
import com.service.ItestService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by b5m on 2017/5/4.
 */
@Controller
@RequestMapping("/test")
public class TestController {

    Logger logger  =  Logger.getLogger(this.getClass());

    @Autowired
    private ItestService itestService;


    /**
     * spring中关于对数据请求的接口
     *
     * */
    @RequestMapping(value = "/get" ,produces = "application/json")
    public @ResponseBody Map<String,Object> get(@RequestBody String jsonData){

        Student student = itestService.selectOne();
        logger.info("开始进入get");
        logger.info("参数"+jsonData);
        Map<String,Object> res = new HashMap<String, Object>();
        res.put("name",student);
        return  res;
    }

    /**
     * spring中关于对页面请求的接口
     *
     * */
    @RequestMapping(value = "/index" ,produces = "application/json")
    public ModelAndView index(){
        logger.info("开始获取页面");
        Map<String,Object> res = new HashMap<String, Object>();
        res.put("name","张三");
        return new ModelAndView("page/one.jsp");
    }
}
